package com.ailiwu.www.ailiwu.views;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ailiwu.www.ailiwu.R;
import com.lidroid.xutils.BitmapUtils;

public class ImageTextButton extends LinearLayout {
    private ImageView iv;
    private TextView tv;
    private BitmapUtils bitmapUtils;

    public ImageTextButton(Context context) {
        super(context);
    }

    public ImageTextButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.image_text_buttton, this,
                true);
        iv = (ImageView) findViewById(R.id.iv);
        tv = (TextView) findViewById(R.id.tv);
        bitmapUtils = new BitmapUtils(context);
    }

    public void setDefaultImageResource(int resId) {
        iv.setImageResource(resId);
    }


    public void setDefaultTextViewText(String text) {
        tv.setText(text);
    }

    /**
     * @param resId
     */
    public void setImageResource(int resId) {
        iv.setImageResource(resId);
    }

    /**
     * 添加bitmap
     */
    public void setImageBitMap(Bitmap bm) {
        iv.setImageBitmap(bm);
    }

    /**设置文字
     * @param text
     */
    public void setText(String text) {
        tv.setText(text);
    }

    /**
     * 设置文字颜色
     */
    public void setTextColor(String color) {
        tv.setTextColor(Color.parseColor(color));
    }

    /**
     * @param color
     */
    public void setTextColor(int color) {
        tv.setTextColor(color);
    }
    /**
     * 加载网络图片
     */
    public void setImageBitmapFromUrl(String url){
        bitmapUtils.display(iv,url);
    }
}